package moxl.parser.assemblers.openelement;

import moxl.parser.ParserException;
import moxl.parser.assemblers.AbstractTokenFedMarkupAssembler;
import moxl.parser.assemblers.AssemblerException;
import moxl.tokenizer.TokenStream;
import moxl.tokenizer.TokenizerException;
import moxl.tokenizer.xml.XmlTokenType;

public class OpenElementAssembler extends AbstractTokenFedMarkupAssembler<OpenElementAssemblerState, OpenElementAssemblerContext>
{
	@Override
	protected OpenElementAssemblerContext createAssemblerContext(TokenStream tstream)
	{
		return new OpenElementAssemblerContext(tstream);
	}

	@Override
	protected void handleInput(XmlTokenType type, OpenElementAssemblerContext ctx) throws ParserException, TokenizerException
	{
		OpenElementStateDelegateBase delegate = ctx.getState().getDelegate();
		switch (type)
		{
		case OPEN_CHEVRON:
			delegate.acceptOpenChevron(ctx);
			break;

		case NAME:
			delegate.acceptName(ctx);
			break;

		case EQUALS:
			delegate.acceptEquals(ctx);
			break;

		case SINGLE_QUOTE:
			delegate.acceptSingleQuote(ctx);
			break;

		case DOUBLE_QUOTE:
			delegate.acceptDoubleQuote(ctx);
			break;

		case ATTRIBUTE_VALUE:
			delegate.acceptAttributeValue(ctx);
			break;

		case SLASH_CLOSE_CHEVRON:
			delegate.acceptSlashCloseChevron(ctx);
			break;

		case CLOSE_CHEVRON:
			delegate.acceptCloseChevron(ctx);
			break;

		case SPACE:
			delegate.acceptSpace(ctx);
			break;

		case WHITESPACE:
			delegate.acceptWhitespace(ctx);
			break;

		default:
			throw new AssemblerException("Parser cannot handle token: " + ctx.getToken(), ctx.getLocation());
		}
	}
}
